package com.second.client.controller;

import com.second.client.pojo.entity.ClientUser;
import com.second.client.pojo.vo.*;
import com.second.client.service.ClientUserService;
import com.second.client.util.UploadUtil;
import com.second.common.pojo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * (ClientUser)表控制层
 *
 * @author LvYongQi
 * @since 2021-07-23 09:53:42
 */
@RestController
@RequestMapping("client")
@Api(tags = "会员管理控制层")
public class ClientUserController {
    /**
     * ClientUserService层服务对象
     */
    @Resource
    private ClientUserService clientUserService;

    /**
     * 查询所有的客户信息
     * @param pageVo 分页工具类
     * @param fuzzyQueryVo 模糊查询工具类
     * @return 所有数据
     */
    @PostMapping("getAllClient")
    @ApiOperation(value = "查询所有的客户信息")
    public R getAllClient(PageVo pageVo, FuzzyQueryVo fuzzyQueryVo) {
        return clientUserService.getAllClient(pageVo,fuzzyQueryVo);
    }

    /**
     * 根据客户Id，改变客户状态
     * @param statusVo 工具类，客户id、状态id
     * @return 修改成功或失败
     */
    @PutMapping("changeClientStaus")
    @ApiOperation(value = "根据客户Id，改变客户状态")
    public R changeClientStaus(ChangeStatusVo statusVo) {
        return clientUserService.changeClientStaus(statusVo);
    }

    /**
     * 根据客户Id修改客户成长值
     *@param statusVo 工具类，客户id、成长值
     *@return 修改成功或失败
     */
    @PutMapping("changeLevelByGrowth")
    @ApiOperation(value = "根据客户Id修改客户成长值")
    public R changeGrowthById (ChangeStatusVo statusVo) {
        return clientUserService.changeGrowthById(statusVo);
    }

    /**
     * 发送验证码
     * @param phone 客户手机号
     * @return 生成结果
     */
    @GetMapping("sendSms")
    @ApiOperation(value = "生成验证码")
    public R sendSms(String phone) {
        return clientUserService.sendSms(phone);
    }

    /**
     * 客户注册
     * @param registerClientVo 注册工具类
     * @return 注册结果
     */
    @PutMapping("registerClient")
    @ApiOperation(value = "客户注册")
    public R registerClient(@RequestBody RegisterClientVo registerClientVo) {
        return clientUserService.registerClient(registerClientVo);
    }

    /**
     * 客户手机号登录
     * @param registerClientVo 工具类
     * @return 登录结果
     */
    @PutMapping("signIn")
    @ApiOperation(value = "客户手机号登录")
    public R signIn(RegisterClientVo registerClientVo) {
        return clientUserService.signIn(registerClientVo);
    }


    /**
     * 客户账号密码登录
     * @param registerClientVo 工具类
     * @return 登录结果
     */
    @PutMapping("signInByup")
    @ApiOperation(value = "客户账号密码登录")
    public R signInByup(@RequestBody RegisterClientVo registerClientVo) {
        return clientUserService.signInByup(registerClientVo);
    }

    /**
     * 增加客户积分
     * @param updateIntegrationVo 修改客户积分工具类
     * @return 增加结果
     */
    @PutMapping("addIntegration")
    @ApiOperation(value = "增加客户积分")
    public R addIntegration(UpdateIntegrationVo updateIntegrationVo) {
        return clientUserService.addIntegration(updateIntegrationVo);
    }

    /**
     * 减少客户积分
     * @param updateIntegrationVo 修改客户积分工具类
     * @return 增加结果
     */
    @PutMapping("reduceIntegration")
    @ApiOperation(value = "减少客户积分")
    public R reduceIntegration(UpdateIntegrationVo updateIntegrationVo) {
        return clientUserService.reduceIntegration(updateIntegrationVo);
    }

    /**
     * 忘记密码？修改密码
     * @param registerClientVo 工具类
     * @return 修改结果
     */
    @PostMapping("updatePwd")
    @ApiOperation(value = "忘记密码，修改密码")
    public R updatePassword(@RequestBody RegisterClientVo registerClientVo) {
        return clientUserService.updatePassword(registerClientVo);
    }

    /**
     * 解析token
     * @return 结果
     */
    @GetMapping("getUserInfo")
    @ApiOperation(value = "解析token")
    public R getUserInfo() {
        return clientUserService.getUserInfo();
    }

    /**
     * 用户租车完善证件资料
     * @param uploadDataVo 用户证件资料
     * @return 上传结果
     */
    @PostMapping("uploadData")
    @ApiOperation(value = "用户租车完善证件资料")
    public R uploadData(@RequestBody UploadDataVo uploadDataVo) {
        return clientUserService.uploadData(uploadDataVo);
    }

    /**
     * 上传照片文件
     * @param file 文件
     * @return 结果
     */
    @RequestMapping("/upload")
    @ApiOperation("上传文件的接口")
    public String Ipload (MultipartFile file) {
        // 将图片回显给前端
        return UploadUtil.getUrl(file).get(0);

    }

    /**
     * 添加/修改用户信息
     * @param clientUser 用户信息实体类
     * @return 添加结果
     */
    @PutMapping("updateClient")
    @ApiOperation(value = "添加用户信息")
    public R updateClient (ClientUser clientUser) {
        return clientUserService.updateClient(clientUser);
    }

    /**
     * 上传用户其他证件信息
     * @param clientUser 用户信息实体类
     * @return 上传结果
     */
    @PutMapping("updateOtherCard")
    @ApiOperation(value = "上传用户其他证件信息")
    public R updateOtherCard (ClientUser clientUser) {
        return clientUserService.updateOtherCard(clientUser);
    }

    /**
     * 修改客户的账户余额,客户积分
     * @param updateIntegrationVo 修改客户余额和积分
     * @return 修改结果
     */
    @PutMapping("updateAccountBalance")
    @ApiOperation(value = "修改客户的账户余额")
    public R updateAccountBalance (@RequestBody UpdateIntegrationVo updateIntegrationVo) {
        return clientUserService.updateAccountBalance(updateIntegrationVo);
    }

    /**
     * 获取会员的账户余额和积分数量
     * @param id 客户id
     * @return 数据结果
     */
    @GetMapping("getBag")
    @ApiOperation(value = "获取会员的账户余额和积分数量")
    public R getBag (Integer id) {
        return clientUserService.getBag(id);
    }

    /**
     * 用户修改头像
     * @param id 用户id
     * @param headPic 用户头像url
     * @return 修改结果
     */
    @GetMapping("updateHeadPic")
    @ApiOperation(value = "用户修改头像")
    public R updateHeadPic (Integer id,String headPic) {
        return clientUserService.updateHeadPic(id,headPic);
    }

    /**
     * 用户修改新密码
     * @param id 用户id
     * @param oldPassword 旧密码
     * @param newPassword 新密码
     * @return 修改结果
     */
    @GetMapping("updateNewPassword")
    @ApiOperation(value = "用户修改新密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id"),
            @ApiImplicitParam(name = "oldPassword",value = "旧密码"),
            @ApiImplicitParam(name = "newPassword",value = "新密码")
    })
    public R updateNewPassword (Integer id,String oldPassword,String newPassword) {
        return clientUserService.updateNewPassword(id,oldPassword,newPassword);
    }

    /**
     * 客户使用余额下单，根据客户id，减去客户的账户余额
     * @param clientId 客户id
     * @param paidAmount 实付金额
     * @return 修改结果
     */
    @GetMapping("deductAccountBalance")
    @ApiOperation(value = "根据客户id，减去客户的账户余额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "clientId",value = "客户id"),
            @ApiImplicitParam(name = "paidAmount",value = "实付金额")
    })
    public boolean deductAccountBalance(Integer clientId,Double paidAmount){
        return clientUserService.deductAccountBalance(clientId,paidAmount);
    }
}
